package io.renren.modules.sys.web_api.controller;

import io.renren.modules.sys.back.service.BtPingpaiInfoService;
import io.renren.modules.sys.web_api.service.FirstPageService;
import io.renren.modules.sys.web_api.service.PinPaiPageService;
import io.renren.modules.sys.web_api.service.RenWuPageService;
import io.renren.modules.sys.web_api.service.WendaPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("api/pinpai")
public class WebPinpaiController {
    @Autowired
    private FirstPageService firstPageService;
    @Autowired
    private PinPaiPageService pinPaiPageService;
    @Autowired
    private BtPingpaiInfoService btPingpaiInfoService;
    @Autowired
    private WendaPageService wendaPageService;
    @RequestMapping("/first")
    public String CrawlerFirst(Map<String,Object> backdata){
        List<Map<String,Object>> fenlei = firstPageService.firstPageProFenLei();
        backdata.put("fenlei",fenlei);
        List<Map<String,Object>> renwu = pinPaiPageService.getPinPaiList();
        backdata.put("renwu",renwu);
        List<Map<String,Object>> rwtuijian=  pinPaiPageService.getPinPaituijan();
        backdata.put("rwtuijian",rwtuijian);
        return "webpage/brands";
    }
    @RequestMapping("/detail/{id}")
    public String CrawlerFirst(@PathVariable("id") Long id, Map<String, Object> backdata){
        if(id<0){
            return "404";
        }
        if(btPingpaiInfoService.selectById(id)==null){
            return "404";
        }
        List<Map<String,Object>> fenlei = firstPageService.firstPageProFenLei();
        backdata.put("fenlei",fenlei);
        Map<String,Object> detailinfo = pinPaiPageService.getPinPaiDatailInfo(id);
        backdata.put("detailinfo",detailinfo);
        List<Map<String,Object>> wenda = wendaPageService.getAllWenda();
        backdata.put("wenda",wenda);
        return "webpage/producdetail";
    }
    @RequestMapping("/setrenwu")
    public void setrenwu( Map<String,Object> backdata){
        pinPaiPageService.SetFirstLeb();
    }
}
